package com.hanggold.jfinal.springboot.lesson1;

import java.util.concurrent.TimeUnit;

/**
 *
 * @author <a href="mailto:sunmch@163.com">smc</a>
 * @date 2021-05-10 08:14
 * @since 1.0.0
 **/
public class ThreadLocalDemo {

	private static ThreadLocal<String> threadLocal = new ThreadLocal<>();

	public static void main(String[] args) throws InterruptedException {
		threadLocal.set("helloworld");
		System.out.println(threadLocal.get());
		//		threadLocal.remove();
		Thread thread = new Thread(() -> {
			System.out.println(Thread.currentThread().getName());
			threadLocal.set("xcc");
			System.out.println("子线程： " + threadLocal.get());
		});
		thread.start();
		thread.join();
		threadLocal.set("cccc");
		for (int i = 1; i < 1000000000; i++) {
			threadLocal.set("xxasdasdaskjdgsadsjhdgasasdasdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
			if (i % 1000 == 0) {
				System.out.println("休息5秒在执行");
				TimeUnit.SECONDS.sleep(5L);
			}
		}
		System.out.println(11);
	}
}
